package com.itheima.web;

import com.itheima.pojo.User;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 徐柯老师
 * @Description
 * @Tel/微信：15074816437
 * @Version 1.0
 **/

@Controller
public class UserController {


    @Autowired
    private IUserService userService;


    @ResponseBody
    @RequestMapping(value="/finduser",method= RequestMethod.GET)
    public List<User> findUsers(){
        return userService.findUsers();
    }


    @ResponseBody
    @RequestMapping(value="/get/{id}",method=RequestMethod.GET)
    public User get(@PathVariable("id")Long id){
        return userService.findById(id);
    }


    @ResponseBody
    @RequestMapping(value="/get2",method=RequestMethod.GET)
    public User get2(@RequestParam("id") Long id){
        return userService.findById(id);
    }

    @ResponseBody
    @RequestMapping(value="/save",method=RequestMethod.POST)
    public int save(@RequestBody  User user){
        return userService.insert(user);
    }

    @ResponseBody
    @RequestMapping(value="/update",method=RequestMethod.POST)
    public int update(@RequestBody  User user){
        return userService.update(user);
    }


    @ResponseBody
    @RequestMapping(value="/delete/{id}",method=RequestMethod.POST)
    public int delete(@PathVariable("id")Long id){
        return userService.deleteById(id);
    }

    @ResponseBody
    @RequestMapping(value="/delete2",method=RequestMethod.POST)
    public int delete2(@RequestParam("id")Long id){
        return userService.deleteById(id);
    }
}

// 对表的增删查改
// 重点什么？删除-----
// 保存或者修改 ,东搞西弄一弄。